<template>
	<view>
		<uni-collapse :accordion="true">
			
			<uni-collapse-item v-for="(item,index) in list" :key="index" :title="item.name" :show-animation="true">
				<uni-list>
					
				</uni-list>
			</uni-collapse-item>
		</uni-collapse>
	</view>
</template>

<script>
	import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
	import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	export default {
		comments: {
			uniCollapse,
			uniCollapseItem,
			uniList,
			uniListItem
		},
		data() {
			return {
				list: []
			}
		},
		onLoad() {
			wx.cloud.init();
			this.getFinance(s => {
				this.list = this.count(s);
				console.log(this.list);
			});
		},
		methods: {
			count(d) {
				d.items = d.items || [];
				d.value = d.items.length > 0 ? 0 : (d.value || 0);
				d.items.forEach(r => {
					r = this.count(r);
					d.value += r.value;
				})
				return d;
			},
			getFinance(s) {
				uni.showLoading();
				wx.cloud.callFunction({
					name: "financeDataBase",
					data: {
						funName: "getFinance",
					}
				}).then(r => {
					if (r && r.result) {
						if (s) s(r.result)
					}
					console.log(r)
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style>

</style>
